﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Info : System.Web.UI.Page
{
    //DropDownList数据源集合
    private List<MyItem> myItems = new List<MyItem>();
    protected void Page_Init(object sender, EventArgs e)
    {
        CreateData();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //定义下拉列表显示项相关属性
        DdlProvnice.DataTextField = "ItemText";
        DdlProvnice.DataValueField = "ItemValue";
        DdlCity.DataTextField = "ItemText";
        DdlCity.DataValueField = "ItemValue";



        if (!IsPostBack)
        {
            //LblTrueName.CssClass = "red";
            //Ddljiguan.Items.Add("天津市");
            //Ddljiguan.Items.Add(new ListItem("天津市","tj"));

            Predicate<MyItem> _p = _f;
            DdlProvnice.DataSource = myItems.FindAll(_p);
            DdlProvnice.DataBind();
            DdlProvnice.SelectedIndex = 0;

            DdlCity.DataSource = myItems.FindAll(delegate(MyItem myItem) {
                return myItem.ItemParent == DdlProvnice.SelectedValue;
            });
            DdlCity.DataBind();

            LbSkill.Items.Add(new ListItem("C语言","c"));
            LbSkill.Items.Add(new ListItem("JAVA语言","java"));
            LbSkill.Items.Add(new ListItem("C#语言","csharp"));

             
            BtnSubmit.Enabled = false;

            Literal2.Mode = LiteralMode.Encode;
            Literal2.Text = "<b>Litera可以拼接HTML字符串</b>";

            //可以展示数据库中的信息
            //BulletedList1.Items.Add("列表项一");
            //BulletedList1.Items.Add("列表项二");
            //BulletedList1.Items.Add("列表项三");
            List<string> _data = new List<string>() { "列表项一", "列表项二", "列表项三" };
            BulletedList1.DataSource = _data;
            BulletedList1.DataBind();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("提交信息成功<br>" );
        LblFav.Text = "选择为：";
        foreach (ListItem item in ChkFav.Items)
        {
            if (item.Selected)
            {
                LblFav.Text += item.Text + "&nbsp";
            }
        }
        if (RBMale.Checked)
        {
            LblGender.Text = RBMale.Text;
        }
        if (RBFemale.Checked)
        {
            LblGender.Text = RBFemale.Text;
        }
        if (RblDegree.SelectedItem != null)
            LblDegree.Text = RblDegree.SelectedItem.Text;
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Write("图片按钮提交成功<br>");
    }

    
    protected void CreateData()
    {
        myItems.Add(new MyItem("bj","北京市","0"));
        myItems.Add(new MyItem("haidian","海淀区","bj"));

        myItems.Add(new MyItem("sh","上海市","0"));
        myItems.Add(new MyItem("xujiahui","徐家汇区","sh"));

        myItems.Add(new MyItem("jx","江西省","0"));
        myItems.Add(new MyItem("nc","南昌市","jx"));

        myItems.Add(new MyItem("gd","广东省","0"));
        myItems.Add(new MyItem("gz","广州市","gd"));

        myItems.Add(new MyItem("hb","湖北省","0"));
        myItems.Add(new MyItem("wh","武汉市","hb"));


    }

    private bool _f(MyItem item)
    {
        return item.ItemParent == "0";
    }

    protected void DdlProvnice_SelectedIndexChanged(object sender, EventArgs e)
    {
        DdlCity.Items.Clear();
        DdlCity.DataSource = myItems.FindAll(myItem => myItem.ItemParent == DdlProvnice.SelectedValue);
        DdlCity.DataBind();
    }

    protected void LbSkill_SelectedIndexChanged(object sender, EventArgs e)
    {
        LblSkill.Text = "";
        for (int i = 0;i<LbSkill.Items.Count;i++)
        {
            if (LbSkill.Items[i].Selected)
            {
                LblSkill.Text += LbSkill.Items[i].Text;
            }
        }
    }

    protected void CheckAgree_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckAgree.Checked)
        {
            BtnSubmit.Enabled = true;
        }
        else
        {
            BtnSubmit.Enabled = false;
        }
    }
}

class MyItem
{
    private string itemValue;
    private string itemText;
    private string itemParent;

    public MyItem(string itemValue, string itemText, string itemParent)
    {
        this.itemValue = itemValue;
        this.itemText = itemText;
        this.itemParent = itemParent;
    }

    public string ItemValue { get => itemValue; set => itemValue = value; }
    public string ItemText { get => itemText; set => itemText = value; }
    public string ItemParent { get => itemParent; set => itemParent = value; }
}